<template>
	<view>
		<!-- pages/user/profit/index.wxml -->
		<!-- 头部 -->
		<navber id="head-navber" :navbarData="navbarData"></navber>
		<!-- 列表 -->
		<view class="coupon-list">
			<coupon v-for="(item,index) in dataList" :key="index" :couponData="item">
			</coupon>
		</view>
	</view>
</template>

<script>
	import navber from '@/components/navber/index';
	import coupon from '@/components/coupon/coupon';
	// pages/user/profit/index.js
	const Config = require('../../../config/index.js');

	const Api = require('../../../api/index.js');

	export default {
		components: {
			navber,
			coupon
		},
		data() {
			return {
				navbarData: {
					title: '我的兑换券' //顶部标题
				},
				//导航栏
				imgUrl: Config.imgUrl,
				//图片
				dataList: [],
				//数据
				pagenow: 1,
			};
		},
		onReachBottom: function(e) {
			//滚动底部
			this.getData();
		},
		onShow() {
			this.setData({
				dataList: [],
				pagenow: 1
			});
			this.getData();
		},
		onPullDownRefresh(e) {
			this.setData({
				dataList: [],
				pagenow: 1
			});
			this.getData();
			uni.stopPullDownRefresh();
		},
		methods: {
			getData() {
				//获取数据
				var json = {
					page: this.pagenow
				};
				Api.getCouponList(json).then((res) => {
					if (res.code == 1) {
						if (res.data) {
							var data = this.dataList;
							data = data.concat(res.data);
							var page = this.pagenow + 1;
							this.setData({
								dataList: data,
								pagenow: page
							});
						} else {
							this.setData({
								dataList: [],
								pagenow: 1
							});
						}
					}
				});
			}
		}
	};
</script>
<style>
	@import './index.css';
</style>
